;; Sri Ganeshji : Sri Balaji : Sri Pitreshwarji : Sri Durgaji : Sri Venkateshwara

/*
Objective(s) -
-	This code demonstrates the usage of Loop Collection
-	To view all vouchers of all cost centre

Syntax -
-	There is an enhancement in syntax of attribute 'Collection' at definition 'Collection'.
-	[Collection : <CollectionName>]
		Collection : <Data Collection Name>[:<Loop Collection Name>[:<Condition for Loop Coll>]]

Last Modification -
-	Altered on 13-01-2010

Company Specifications -
-	Cost Centres should be activated
-	Vouchers using cost centres should be created
*/

[Report: CCVouchersRep]
	
	Form		: CCVouchersForm
	Variable	: SVFromDate, SVToDate
	Title		: $$LocaleString:"Cost Centre Vouchers"
	Set			: SVFromDate			: ##SVCurrentDate
	Set			: SVToDate				: ##SVCurrentDate
		
[Form: CCVouchersForm]
	
	Parts		: CCVouchersPartTitle, CCVouchersPartCmpName
	Buttons		: F2 Change Period
	Width		: 100% Screen
	Background  : @@SV_COSTCATEGORY
	
[Part: CCVouchersPartTitle]

	Lines	: CCVouchersTitle
	
[Part: CCVouchersPartCmpName]

	Lines 	: CCVouchersLineCmpName
	Repeat	: CCVouchersLineCmpName		: CostCentreColl
	Scroll	: Vertical

	[Line: CCVouchersLineCmpName]

		Fields		: CCVouchersLineCmpName
		Explode 	: CCVouchersPart 	: Yes
		Space Bottom: 0.25
		Space Top	: if $$Line = 1 then 0 else 1.0

		[Field: CCVouchersLineCmpName]
			
			Use			: Name Field
			Border		: Thick Bottom
			Set as 		: $Name
			Align		: Center

;; Explode to vouchers
	
	[Part: CCVouchersPart]

		Lines	: CCVouchersDetails
		Repeat	: CCVouchersDetails	: CCVoucherLoopCollection ;; For this we have created a loop collection
		Scroll	: Vertical
		
		[Line: CCVouchersTitle]
			
			Use		: CCVouchersDetails
			
			Local	: Field	: Default		: Type		: String
			Local	: Field	: Default		: Align		: Center
			Local	: Field	: Default		: Lines		: 0
			
			Local	: Field	: CCVchDate		: Set as	: "Date"
			Local	: Field	: CCVchLed		: Set as	: "Ledger Name"
			Local	: Field	: CCVchVType	: Set as	: "Vch Type"
			Local	: Field	: CCVchVno		: Set as	: "Vch No."
			Local	: Field	: CCVchCCAmt	: Set as	: "Amount"
			
			Border	: Top Thick Bottom Thin
			
		[Line: CCVouchersDetails]
			
			Fields		: CCVchDate, CCVchCCName , CCVchLed
			RightFields	: CCVchVType, CCVchVno, CCVchCCAmt
			Remove if	: #CCVchCCName != #CCVouchersLineCmpName
			
			[Field: CCVchDate]
				
				Use			: Uni Date Field
				Set as		: $Date
				Style		: Small

			[Field: CCVchCCName]
				
				Use			: Short Name Field
				Set as		: $CCName
				Invisible	: Yes
				
			[Field: CCVchLed]
				
				Use			: NameField
				Set as		: $LedgerName
				
			[Field: CCVchVType]
				
				Use			: Short Name Field
				Set as		: $VoucherTypeName
				Width		: 12
				
			[Field: CCVchVno]
				
				Use			: Voucher Number Field
				Set as		: $VoucherNumber
				Width		: 8
				Align		: Right
				Style		: Normal
				
			[Field: CCVchCCAmt]

				Use			: Amount Field
				Set as		: $VchCCAmt

[#Object: Voucher]

	VchCCAmt	: $$CollAmtTotal:AllLedgerEntries:$LedCCAmt

[#Object: LedgerEntry]

	LedCCAmt	: $$CollAmtTotal:CategoryAllocations:$CCatCCAmt
				
[#Object: Category Allocations]

	CCatCCAmt	: $$FilterAmtTotal:CostCentreAllocations:SmpCCFilter:$Amount

[System: Formula]

	Smp CC Filter	: $Name = #CCVouchersLineCmpName

;; Collection for Repeat Collection

[Collection: CCVoucherLoopCollection]
	
	Collection	: VchOfCostCentre 	: CostCentreColl
/*
We require vouchers of cost centre, however we would need to filter out those cost 
centre which have been used for payroll. Collection 'VchOfCostCentre' is our base 
collection from which we need to retrieve the data. Collection 'CostCentreColl' is 
the basis on which we require the vouchers to be filtered
*/
	Sort		: Default			: $CCName, $Date, $Amount
	
[Collection: VchOfCostCentre]

	Type		: Vouchers	: Cost Centre
	Child Of	: $Name ;; This refers to collection 'Cost Centre'
	Fetch		: Date, LedgerName, VoucherTypeName, VoucherNumber, Amount, VchCCAmt
	Compute		: CCName	: $$LoopCollObj:$Name ;; We need cost centre name for filtering value at line level

/*
Incase you require any values of Loop collection to be fetched in your base collection 
you need to make use of function $$LoopCollObj
*/
		
[Collection: CostCentreColl]
	
	Type	: Cost Centre
	Filter	: NoEmp
	Fetch	: Name

;; Border for Title Line

[Border: Top Thick Bottom Thin]
	
	Top         : Thick
    Bottom      : Thin
	
[System: Formulae]
	
	NoEmp 		: $ForPayroll = "No"

;; End-of-File
